local nianying2 = fk.CreateSkill {

  name = "joy__nianying2",

  tags = {  },

}



nianying2:addEffect(fk.Damage, {
  name = "joy__nianying2",
  anim_type = "special",
  events = {fk.Damage,fk.Damaged},
  can_trigger = function(self, event, target, player, data)
      if target ~= player or not player:hasSkill(nianying2.name) or player:usedSkillTimes(nianying2.name, Player.HistoryTurn) ~= 0 then return end
      if event == fk.Damage then
        local n = 0
        player.room.logic:getActualDamageEvents( 3, function(e)
      local damage = e.data
      if damage.from  and damage.from == player then
        n = n + damage.damage
      end
    end)
        return n >= 2
      elseif event == fk.Damaged then
        local n = 0
        player.room.logic:getActualDamageEvents( 3, function(e)
      local damage = e.data
      if damage.to and damage.to == player then
        n = n + damage.damage
      end
    end)
        return n >= 2
      end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player,nianying2.name,nil,"念影：你可以执行一项“念影”效果。")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    nianying(player)
  end,
})
nianying2:addEffect(fk.Damaged, {
  name = "joy__nianying2",
  anim_type = "special",
  events = {fk.Damage,fk.Damaged},
  can_trigger = function(self, event, target, player, data)
      if target ~= player or not player:hasSkill(nianying2.name) or player:usedSkillTimes(nianying2.name, Player.HistoryTurn) ~= 0 then return end
      if event == fk.Damage then
        local n = 0
        player.room.logic:getActualDamageEvents( 3, function(e)
      local damage = e.data
      if damage.from  and damage.from == player then
        n = n + damage.damage
      end
    end)
        return n >= 2
      elseif event == fk.Damaged then
        local n = 0
        player.room.logic:getActualDamageEvents( 3, function(e)
      local damage = e.data
      if damage.to and damage.to == player then
        n = n + damage.damage
      end
    end)
        return n >= 2
      end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player,nianying2.name,nil,"念影：你可以执行一项“念影”效果。")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    nianying(player)
  end,
})

return nianying2